package resource.loaders
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	
	import resource.event.LoadResEvent;
	
	public class SwfLoader extends EventDispatcher implements IResLoader
	{
		protected var _loader:Loader;
		private var _url:String;
		private var _resId:String;
		
		public function SwfLoader()
		{
			_loader = new Loader();
		}
		
		public function load(url:String = ""):void
		{
			if(url != "")
				_url = url;
			_loader.load(new URLRequest(_url));
			_loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
		}
		
		
		public function getData():*
		{
			return Bitmap(_loader.contentLoaderInfo.content).bitmapData;
		}
		
		private function ioErrorHandler(event:IOErrorEvent):void
		{
			trace(event.toString());
		}
		
		private function completeHandler(event:Event):void
		{
			dispatchEvent(new LoadResEvent(LoadResEvent.LOAD_OK));
		}
	
		public function get url():String
		{
			return _url;
		}
		
		public function set url(value:String):void
		{
			_url = value;
		}
		
		public function get resId():String
		{
			return _resId;
		}
		
		public function set resId(value:String):void
		{
			_resId = value;
		}
		//
	}
}